define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                    bankInfo: {},
                    showType:1,
                     bankList:[],

                    bankSubbranchList:[],
                    contactline:'',
                    MerchantName:'',
                    MerchantId:'',
                    Fee:0,
                };
            },
            el: '#pageBankInfo',
            created: function() {
                this.fetchData();
                 app.area(".bankArea");
            },
            methods: {
                fetchData: function() {
                    var _this = this;
                     this.getBank();
                    this.getBankInfo(); 
                },
                getBankInfo:function(){
                    var that = this;
                    if( that.loading == 1){
                        return ;
                     }
                     that.loading = 1;
                    
                    var user_info =  app.getUserInfo();
                    
                    app.get("apiv2/mch_my_bank/merchantInfo", {
                       
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      that.bankInfo = res.data.BankCardParam;
                      // that.MerchantDetail = res.data.MerchantDetail;
                      that.MerchantName=  res.data.MerchantName;
                      that.MerchantId =  res.data.MerchantId;
                      that.Fee = (res.data.FeeParamList[0].FeeValue)*100+"%";

                      
                      
                    });
                },
                getBank:function(){
                    var that = this;
                    app.get("apiv2/bank/getBank", {
                      
                    }, function (res) {
                      
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      that.bankList = res.data;
        
                    });
                },
                getBankSubbranch:function(){
                    var that = this;
                    var data={};
                     
                    data.bankId=$("[name='BankName']").val();
                    // data.city_name=$("#bankCity").find("option:selected").text();
                    data.city_name=$("#bankCity option:selected").text();
                    if(!data.city_name){
                      return ;
                    }
                    app.get("apiv2/bank/getBankSubbranch", data, function (res) {
                      
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      that.bankSubbranchList = res.data;
                      
                    });
                },
                setContactLine:function(){
                        var value = $("[name='BranchName']").val();
                        this.contactline=$("[name='BranchName']").find("[value='"+value+"']").attr("contactline");
                },
                saveBankInfo:function(){
                   var that = this;
                   var data = $("#bankInfoForm").serializeArray();
                    data.push({
                        name:"method",
                        value:'updateMerchantBankCard'
                    });
                   app.post("/apiv2/mch_my_bank",data,function(res){
                       if(res.code!=200){
                        app.alert(res.msg);
                        return;
                       }
                       app.alert("修改成功");
                       that.getBankInfo();
                       that.showType=1;
                   });
                }
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
